﻿// Copyright (c) Inossem. All rights reserved.
// Licensed under the LGPL-3.0 license. See LICENSE file in the project root for full license information.
using DWF.Common.Activities.Contract;
using DWF.Studio.ScriptEngine.Event;
using DWF.Studio.ScriptEngine.Implementation;
using DWF.Studio.ScriptEngine.IPC.Msg;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DWF.Studio.ScriptEngine.Custom
{
    internal class WorkflowScriptEngineService : IScriptEngineService
    {
        private string _parentEngineId = null;

        private bool _isDebug = false;

        public WorkflowScriptEngineService(string parentEngineId, bool isDebug = false)
        {
            _parentEngineId = parentEngineId;
            _isDebug = isDebug;
        }

        public object ExcuteWorkflow(string projectDirectory, string scriptPath, Dictionary<string, object> param)
        {
            var scriptEngine = new WorkflowScriptEngineSub(ExecutionContext.Instance);
            ExecutionContext.Instance.WaitSubEngineProxyLoaded(projectDirectory, scriptPath, scriptEngine.Id, EEngineType.WorkflowScriptEngine, _parentEngineId);

            if (_isDebug)
            {
                scriptEngine.DebugScript(projectDirectory, scriptPath, param);
            }
            else
            {
                scriptEngine.ExecuteScript(projectDirectory, scriptPath, param);
            }

            return scriptEngine.ExcuteResult;
        }

        public object ExcuteIronPython(string projectDirectory, string scriptPath, Dictionary<string, object> param) => throw new NotImplementedException();

        public object ExcuteJScript(string projectDirectory, string scriptPath, Dictionary<string, object> param) => throw new NotImplementedException();

        public object ExcuteVbScript(string projectDirectory, string scriptPath, Dictionary<string, object> param) => throw new NotImplementedException();
    }
}
